﻿<%@ Page Language="c#" MasterPageFile="~/Default.master" Title="Untitled Page" %>
<%@ Register TagPrefix="Club" TagName="ImageThumbnail" Src="ImageThumbnail.ascx" %>
<%@ Register TagPrefix="Club" Namespace="ClubSite" %>
<script runat="server">

    string ShowDuration(object starttime, object endtime)
    {
        System.DateTime starttimeDT = (DateTime)starttime;
        if (endtime != null && endtime != DBNull.Value)
        {
            System.DateTime endtimeDT = (DateTime)endtime;
            if (starttimeDT.Date == endtimeDT.Date)
            {
                if (starttimeDT == endtimeDT)
                {
                    return starttimeDT.ToString("h:mm tt");
                }
                else
                {
                    return starttimeDT.ToString("h:mm tt") + " - " + endtimeDT.ToString("h:mm tt");
                }
            }
            else
            {
                return "thru " + endtimeDT.ToString("d");
            }
        }
        else
        {
            return starttimeDT.ToString("h:mm tt");
        }
    }

    void logout_click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        
    } 
    
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="body">
        <!--Start of left column-->
        <div id="columnleft">
            <a name="content_start" id="content_start"></a>
            <div class="leftblock">
                <h2>
                    Welcome</h2>
                <p>
                    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
                    euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
                    minim veniam, quis nostrud exercitation ulliam corper suscipit lobortis nisl ut
                    aliquip ex ea commodo consequat. Duis autem veleum iriure dolor in hendrerit in
                    vulputate velit esse molestie consequat, vel willum lunombro dolore eu feugiat nulla
                    facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent
                    luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
            </div>
            <div class="leftblock">
                <asp:LoginView ID="lv1" runat="server">
                    <AnonymousTemplate>
                        <h2>
                            Login</h2>
                        <div class="dashedline">
                        </div>
                        <asp:Login ID="Login1" runat="server">
                            <LayoutTemplate>
                                <h3 class="none">
                                    Log into My Club Site</h3>
                                <fieldset>
                                    <legend class="none">Log into My Club Site</legend>
                                    <asp:Label runat="server" AssociatedControlID="UserName" ID="UserNameLabel">User name:</asp:Label>
                                    <br />
                                    <asp:TextBox runat="server" ID="UserName"></asp:TextBox>
                                    <asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" ValidationGroup="Login1"
                                        ErrorMessage="User Name is required." ToolTip="User Name is required." ID="UserNameRequired">*</asp:RequiredFieldValidator>
                                    <p>
                                    </p>
                                    <asp:Label runat="server" AssociatedControlID="Password" ID="PasswordLabel">Password:</asp:Label>
                                    <br />
                                    <asp:TextBox runat="server" TextMode="Password" ID="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator runat="server" ControlToValidate="Password" ValidationGroup="Login1"
                                        ErrorMessage="Password is required." ToolTip="Password is required." ID="PasswordRequired">*</asp:RequiredFieldValidator>
                                    <p>
                                    </p>
                                    <asp:CheckBox runat="server" ID="RememberMe" Text="Remember me next time." />
                                    <p>
                                    </p>
                                    <Club:RolloverButton runat="server" ValidationGroup="Login1" Text="Login" ID="LoginButton"
                                        CommandName="Login" />
                                    <p>
                                    </p>
                                    <asp:Literal runat="server" ID="FailureText" EnableViewState="False"></asp:Literal>
                                </fieldset>
                            </LayoutTemplate>
                        </asp:Login>
                    </AnonymousTemplate>
                    <LoggedInTemplate>
                        <h2>
                            Hello
                            <asp:LoginName ID="LoginName1" runat="server" />
                        </h2>
                        <p>
                            Welcome back to the clubsite.
                        </p>
                        <Club:RolloverButton runat="server" id="logout" text="Log off" onclick="logout_click" />
                    </LoggedInTemplate>
                </asp:LoginView>
            </div>
        </div>
        <!--end columnleft-->
        <!--Start of right column-->
        <div id="columnright">
            <!-- Start of news list functionality -->
            <div class="rightblock">
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ProviderName="System.Data.SqlClient"
                    ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>" SelectCommand="SELECT top 5 [id], [itemdate], [title], [description], [photo] FROM [Announcements] order by itemdate desc">
                </asp:SqlDataSource>
                <h2>
                    Recent news</h2>
                <div class="dashedline">
                </div>
                <asp:Repeater ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
                    <ItemTemplate>
                        <div class="listitem">
                            <div class="thumbnail">
                                <a href='<%# "News_View.aspx?Articleid=" + Convert.ToString(Eval("ID"))%>'>
                                    <Club:ImageThumbnail ID="ImageThumbnail2" runat="server" PhotoID='<%# Eval("photo") %>'
                                        NoPhotoImg="images/news.jpg" />
                                </a>
                            </div>
                            <h3>
                                <asp:Label ID="Label3" runat="server" Text='<%# Eval("itemdate","{0:d}") %>' />
                                &nbsp;&nbsp;&nbsp;&nbsp; <a href='<%# "News_View.aspx?Articleid=" + Convert.ToString(Eval("ID"))%>'>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Eval("title") %>' />
                                </a>
                            </h3>
                            <p>
                                <asp:Label ID="Label2" runat="server" Text='<%# SharedRoutines.truncate((string)Eval("description")) %>' />
                                <a href='<%# "News_View.aspx?Articleid=" + Convert.ToString(Eval("ID")) %>'>read more &raquo;</a>
                            </p>
                            <div class="clearlist"></div>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
                <div class="dashedline">
                </div>
                <a href="news_list.aspx">Read all news articles &raquo;</a>
            </div>
            <div class="rightblock">
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
                    SelectCommand="SELECT top 2 dbo.Events.id, dbo.Events.starttime, dbo.events.endtime, dbo.Events.title, dbo.Locations.title AS locationname FROM dbo.Events LEFT OUTER JOIN dbo.Locations ON dbo.Events.location = dbo.Locations.id WHERE     (dbo.Events.starttime > GETDATE()) ORDER BY dbo.Events.starttime, dbo.events.id ">
                </asp:SqlDataSource>
                <h2>
                    Upcoming Events</h2>
                <div class="dashedline">
                </div>
                <asp:GridView AutoGenerateColumns="False" DataSourceID="SqlDataSource2" ID="GridView1"
                    runat="server" ShowHeader="False" Width="410px" CssClass="eventlist" GridLines="None">
                    <Columns>
                        <asp:BoundField DataField="starttime" DataFormatString="{0:d}" HeaderText="starttime"
                            SortExpression="starttime"></asp:BoundField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:HyperLink ImageUrl="images/icon_event.gif" runat="server" NavigateUrl='<%# Eval("id","Events_download.ashx?Eventid={0}") %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="id" InsertVisible="False" SortExpression="id">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# ShowDuration(Eval("starttime"),Eval("endtime")) %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:HyperLinkField DataNavigateUrlFields="id" DataNavigateUrlFormatString="events_view.aspx?eventid={0}"
                            DataTextField="title"></asp:HyperLinkField>
                        <asp:BoundField DataField="locationname" HeaderText="locationname" SortExpression="locationname"
                            NullDisplayText=""></asp:BoundField>
                    </Columns>
                </asp:GridView>
                <div class="dashedline">
                </div>
                <a href="Events_list.aspx">View all events &raquo;</a>
            </div>
        </div>
        <div class="clear2column"></div>
    </div>
</asp:Content>
